package com.gitee.liuzhi.demo.juc.threadpoolexecutor;

import com.gitee.liuzhi.demo.juc.threadpoolexecutor.task.MyCallable;
import com.gitee.liuzhi.demo.juc.threadpoolexecutor.task.MyRunnable;
import com.gitee.liuzhi.demo.juc.threadpoolexecutor.threadpool.MyThreadPoolExecutor;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author liuzhi
 * @Date 2023/9/6 20:39
 * @Version 1.0
 * @Description
 */
@Slf4j
public class Main {

    private static final Integer END = 100;

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = MyThreadPoolExecutor.getInstance();
        // use runnable
        for (int i = 0; i < END; i++) {
            MyRunnable myRunnable = new MyRunnable();
            threadPoolExecutor.execute(myRunnable);
        }
        // use callable
        for (int i = 0; i < END; i++) {
            MyCallable myCallable = new MyCallable();
            Future future = threadPoolExecutor.submit(myCallable);
            log.info("main thread consume number : {}", future.get());
        }
    }

}
